<?php 
//QQ登录
function qq_login()
{
	Vendor('QQConnect.API.qqConnectAPI');
	$qc = new QC();
	$qc->qq_login();
}
//获取openid
function getOpenid()
{
	Vendor('QQConnect.API.qqConnectAPI');
	$qc = new QC();
	$qc->qq_callback();
    return $qc->get_openid();
}

//获取用户信息
function getUserInfo()
{
	Vendor('QQConnect.API.qqConnectAPI');
	$qc = new QC();
	return $qc->get_user_info();
}

function getQQFace($url)
{
	//初始化
	$ch = curl_init();
	//设置选项，包括URL
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	//执行并获取HTML文档内容
	$output = curl_exec($ch);
	//释放curl句柄
	curl_close($ch);
	//打印获得的数据
	$path = "Uploads/qq/".uniqid().".jpg";

	file_put_contents($path,$output);

	return $path;
}
//发邮件
 function qqmail($email,$title,$str)
{

	Vendor('PHPMailer.PHPMailerAutoload');

	$mail = new PHPMailer;

	//$mail->SMTPDebug = 3;                               // Enable verbose debug output

	$mail->isSMTP();                                      // Set mailer to use SMTP
	$mail->Host = 'smtp.qq.com';  // Specify main and backup SMTP servers
	$mail->SMTPAuth = true;                               // Enable SMTP authentication
	$mail->Username = '113664000@qq.com';                 // SMTP username
	$mail->Password = 'dbvezbqyvjckbjag';                           // SMTP password
	$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
	$mail->Port = 465;                                    // TCP port to connect to

	$mail->setFrom('113664000@qq.com', '学并思');
	$mail->addAddress($email, 'Joe User');     // Add a recipient
	// $mail->addAddress('ellen@example.com');               // Name is optional
	// $mail->addReplyTo('info@example.com', 'Information');
	// $mail->addCC('cc@example.com');
	// $mail->addBCC('bcc@example.com');

	// $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
	// $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
	$mail->isHTML(true);                                  // Set email format to HTML

	$mail->Subject = $title;
	$mail->Body    = $str;
	// $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

	if(!$mail->send()) {
	    echo 'Message could not be sent.';
	    echo 'Mailer Error: ' . $mail->ErrorInfo;
	} else {
	    echo 'Message has been sent';
	}
}


//格式化时间
function getFormate($time)
{
	$diff = time()-$time;
	if($diff<60){
		return "刚刚";
	}elseif($diff<3600){
		return floor($diff/60)."分钟前";
	}elseif($diff<86400){
		return floor($diff/3600)."小时前";
	}elseif($diff<(86400*7)){
		return floor($diff/86400)."天前";
	}else{
		return date('Y-m-d H:i:m',$time);
	}
}

//中文分词
function  getWords($w)
{
	// 加入头文件
	// require '/path/to/pscws4.class.php';

	Vendor('Pscws4.pscws4','','.class.php');

	// 建立分词类对像, 参数为字符集, 默认为 gbk, 可在后面调用 set_charset 改变
	$pscws = new PSCWS4('utf8');

	$pscws->set_dict('./Public/dict.utf8.xdb');
	$pscws->set_rule('./ThinkPHP/Library/Vendor/Pscws4/etc/rules.ini');

	$pscws->send_text($w);

	// while ($some = $pscws->get_result())
	// {
	//    foreach ($some as $word)
	//    {
	//       var_dump($word);
	//    }
	// }

	$tops = $pscws->get_tops(3, 'n,v');

	return $tops;

	// var_dump($pscws);
}










 ?>